import sys, xlrd, csv

# inputFile  = '../data/raw_data/census/Revenu_Pauvrete/2012/revenu-pauvrete-menage-2012/base-cc-filosofi-12.xls'
# outputFile = '../data/raw_data/census/Revenu_Pauvrete/2012/revenu-pauvrete-menage-2012/base-cc-filosofi-12_COM.csv'
# inputSheetName = 'COM'
# firstRow2Keep = 5

[inputFile, outputFile, inputSheetName, firstRow2Keep] = sys.argv[1:6]
firstRow2Keep = int(firstRow2Keep)

wb = xlrd.open_workbook(inputFile)
sh = wb.sheet_by_name(inputSheetName)
fout = open(outputFile, 'w', encoding='utf8')
wr = csv.writer(fout, quoting=csv.QUOTE_NONE)
for rownum in range(firstRow2Keep,sh.nrows):
    myvalue = sh.row_values(rownum)
    wr.writerow(sh.row_values(rownum))

fout.close()
